<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文</title>
<link href="../../../static/css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>仓库管理</li>
    <li>仓库浏览</li>
    <li>基本内容</li>
  </ul>
</div>
<div class="rightinfo">
  <form action="" method="post">
    <ul class="tools">
      <li>仓库名称:
        <input maxlength="30" type="text" id="storageName"/>
      </li>
      <li> 所属区域：
        <select class="province" onchange="provinceChange()">
<!--          <option>请选择省份</option>-->
<!--          <option>北京</option>-->
<!--          <option>江苏</option>-->
<!--          <option>天津</option>-->
        </select>
        <select class="city">
<!--          <option >请选择城市</option>-->
<!--          <option>北京</option>-->
<!--          <option>南京</option>-->
<!--          <option>天津</option>-->
        </select>
      </li>
      <li class="subBut" id="searchBtn"><img src="../../../static/images/t06.png" />查询</li>
    </ul>
    <table class="tablelist" id="storageBrowse">
      <thead>
      <tr>
        <th>序号</th>
        <th>仓库名称</th>
        <th>负责人</th>
        <th>联系电话</th>
        <th>所属区域</th>
        <th>状态</th>
        <th>创建时间</th>
        <th>创建人</th>
        <th>操作</th>
      </tr>
      </thead>
      <tbody>
      <tr>
        <td>1</td>
        <td>南京21号仓库</td>
        <td>朱元璋</td>
        <td>17370899727</td>
        <td>江苏南京</td>
        <td>可用</td>
        <td>2013-09-09 15:05:05</td>
        <td>马云</td>
        <td>
          <a href="storageView.html" class="tablelink">查看详情</a>
        </td>
      </tr>
      <tr>
        <td>2</td>
        <td>武汉71号仓库</td>
        <td>周瑜</td>
        <td>17370899727</td>
        <td>湖北武汉</td>
        <td>不可用</td>
        <td>2013-09-09 15:05:05</td>
        <td>马化腾</td>
        <td>
          <a href="storageView.html" class="tablelink">查看详情</a>
        </td>
      </tr>
      <tr>
        <td>3</td>
        <td>南京21号仓库</td>
        <td>朱元璋</td>
        <td>17370899727</td>
        <td>江苏南京</td>
        <td>可用</td>
        <td>2013-09-09 15:05:05</td>
        <td>马云</td>
        <td>
          <a href="storageView.html" class="tablelink">查看详情</a>
        </td>
      </tr>
      <tr>
        <td>4</td>
        <td>武汉71号仓库</td>
        <td>周瑜</td>
        <td>17370899727</td>
        <td>湖北武汉</td>
        <td>不可用</td>
        <td>2013-09-09 15:05:05</td>
        <td>马化腾</td>
        <td>
          <a href="storageView.html" class="tablelink">查看详情</a>
        </td>
      </tr>
      </tbody>
    </table>
    <div class="pagin">
      <div class="message">共<i class="blue" id="total">0</i>条记录，当前显示第&nbsp;<i class="blue" id="current">1&nbsp;</i>页</div>
      <ul class="paginList" id="pagelistNum">
        <li class="paginItem"><a href="javascript:;"><span class="pagepre"></span></a></li>
        <li class="paginItem"><a href="javascript:;">1</a></li>
        <li class="paginItem current"><a href="javascript:;">2</a></li>
        <li class="paginItem"><a href="javascript:;">3</a></li>
        <li class="paginItem"><a href="javascript:;">4</a></li>
        <li class="paginItem"><a href="javascript:;">5</a></li>
        <li class="paginItem more"><a href="javascript:;">...</a></li>
        <li class="paginItem"><a href="javascript:;">10</a></li>
        <li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>
      </ul>
    </div>
  </form>
  <!-- 提示框 -->
<!--  <div id="tip" class="tip">-->
<!--    <div class="tiptop"><span>提示信息</span><a onclick="tipClose()"></a></div>-->
<!--    <div class="tipinfo"> <span><img src="../../images/ticon.png" /></span>-->
<!--      <div class="tipright">-->
<!--        <p></p>-->
<!--        <cite>如果是请点击确定按钮 ，否则请点取消。</cite> </div>-->
<!--    </div>-->
<!--    <div class="tipbtn">-->
<!--      <input name="" type="button"  class="sure" value="确定" onclick="tipClose()" />-->
<!--      &nbsp;-->
<!--      <input name="" type="button"  class="cancel" value="取消" onclick="tipClose()" />-->
<!--    </div>-->
<!--  </div>-->
</div>
<script type="text/javascript" src="../../../static/js/jquery.js"></script>
<script type="text/javascript">
	// $('.tablelist tbody tr:odd').addClass('odd');


    var isSerch = false;
    $(function () {
      getAddressInfo();
      loadstorages(1);
      // 搜索点击事件
      $("#searchBtn").on("click", function () {
        isSerch = true;
        // alert($('.city').val());
        // alert($('.province').val())
        loadstorages(1);
      })

    });

    //全局信息
    window.datas = {
      //查询条件
      conditionInfo: {
        pageNum: "1",
        pageSize: "4",
        condition: {
          company: ''
        }
      },
      //查询信息
      resultInfo: {},
      //地区信息
      addressInfo:[],
    };
    //获取地区信息
    function getAddressInfo() {
      $.ajax({
        url: "/commonProvince",
        type: "get",
        dataType: "json",
        success: (data) => {
          window.datas.addressInfo = data.data;
          $(".province").html('<option value="">请选择省份</option>')
          window.datas.addressInfo.forEach((item, index) => {
            $(".province").append(`<option name="${item.id}" value="${item.pname}">${item.pname}</option>`)
          })
        }
      })
    }

    //选择省份之后
    function provinceChange() {
      let addressInfo = datas.addressInfo;
      let city = [];
      let id = $(".province option:selected").attr("name");
      for (let i = 0; i < addressInfo.length; i++) {
        if (addressInfo[i].id == id) {
          city = addressInfo[i].citys;
          break;
        }
      }
      $(".city").html('<option value=""></option>')
      city.forEach((item, index) => {
        $(".city").append(`<option value="${item.cname}">${item.cname}</option>`);
      })

    }

    //加载仓库列表
    function loadstorages(currentPage) {
      let province;
      let city;
      let storageName;
      if (isSerch) {
        province = $('.province').val();
        city = $('.city').val();
        storageName = $('#storageName').val();
        // alert(storageName)
      }

      let nowUser = JSON.parse(localStorage.getItem("user"));//当前用户
      let nowUserID = nowUser.uid;
      //跳转servlet路径、传入参数、获取返回值——页面片段并显示！
      $.ajax({
        type: "GET",//请求类型
        url: "/Warehouse/WarehousePage",//请求的url
        data: {
          province: province,
          city: city,
          cNamelike: storageName,
          userID:nowUserID,
          pageNum: currentPage,
          pageSize: 4
        },//请求参数
        dataType: "json",//ajax接口（请求url）返回的数据类型
        success: function (pb) {
          pb = pb.data;
          $("#total").html(pb.totalCount)
          $("#current").html(pb.pageNum)
          //1.展示分页页码
          var lis = "";
          //上一页
          var beforenum = pb.pageNum - 1;
          if (beforenum <= 0) {
            beforenum = 1;
          }
          var beforePage = '<li class="paginItem" onclick="loadstorages(' + beforenum + ')"><a href="javascript:;"><span class="pagepre"></span></a></li>';
          lis += beforePage;

          // 1,2,3,4...
          // 定义开始位置begin,结束位置 end
          var begin; // 开始位置
          var end; //  结束位置

          //要显示6个页码
          if (pb.totalPage < 6) {
            //总页码不够10页
            begin = 1;
            end = pb.totalPage;
          } else {
            //总页码超过6页
            begin = pb.pageNum - 3;
            end = pb.pageNum + 2;
            //2.如果前边不够3个，后边补齐6个
            if (begin < 1) {
              begin = 1;
              end = begin + 5;
            }
            //3.如果后边不足2个，前边补齐6个
            if (end > pb.totalPage) {
              end = pb.totalPage;
              begin = end - 5;
            }
          }
          for (var i = begin; i <= end; i++) {
            var li;
            //判断当前页码是否等于i
            if (pb.pageNum == i) {
              li = '<li class="paginItem current" onclick="loadstorages(' + i + ')"><a href="javascript:;">' + i + '</a></li>';
            } else {
              //创建页码的li
              li = '<li class="paginItem" onclick="loadstorages(' + i + ')"><a href="javascript:;">' + i + '</a></li>';
            }
            //拼接字符串，加入页面中
            lis += li;
          }

          //下一页
          var nextnum = pb.pageNum + 1;
          if (nextnum > pb.totalPage) {
            nextnum = pb.totalPage;
          }
          var nextPage = '<li class="paginItem" onclick="loadstorages(' + nextnum + ')"><a href="javascript:;"><span class="pagenxt"></span></a></li>';
          lis += nextPage;

          $("#pagelistNum").html(lis);//显示

          // 3.显示当前页列表
          var storage_lis = '';
          for (var i = 0; i < pb.data.length; i++) {

            var storage = pb.data[i];//该页路线数据显示        showOrder(id)
            let states = "";

            var storageli =
                    '<tr>' +
                    '<td>' +
                    '<span>' + ((pb.pageNum - 1) * 4 + i + 1) + '</span>' +
                    '</td>' +
                    '<td>' +
                    '<span>' + storage.cname + '</span>' +
                    '</td>' +
                    '<td>' +
                    '<span>' + storage.usre + '</span>' +
                    '</td>' +
                    '<td>' +
                    '<span>' + storage.phone + '</span>' +
                    '</td>' +
                    '<td>' +
                    '<span>' + storage.caddress + '</span>' +
                    '</td>' +
                    '<td>' +
                    '<span>' + states + '</span>' +
                    '</td>' +
                    '<td>' +
                    '<span>' + storage.creationTime + '</span>' +
                    '</td>' +
                    '<td>' +
                    '<span>' + storage.users + '</span>' +
                    '</td>' +
                    '<td>' +
                    '<a href="/storage/storage/storageView?id='+storage.id+'" class="tablelink">查看详情</a>&nbsp;&nbsp;'+
                    '</td>' +
                    '</tr>';
            storage_lis += storageli;
          }
          $("#storageBrowse tbody").html(storage_lis);

        }
      })
    }

</script>
</body>
</html>
